%==========================================================================
%=  This file is part of the Sound Restoration Project
%=  (c) Copyright Interdisciplinary Mathematics Institute
%=                University of South Carolina, Department of Mathematics
%=  ALL RIGHTS RESERVED
%=
%=  Author: Borislav Karaivanov
%==========================================================================

%==========================================================================
% List of the files on which this procedure depends:
%
% none
%
%==========================================================================

%==========================================================================
% The function "partitionFileName" takes the name (including a full
% directory path) of a single file and partitions it into three strings:
% its parent directory (including a full directory path), the file name
% with directory path and file extension are removed, and the file
% extension.
% INPUT: "fileName" is a string specifying a file name (including a full
% directory path).
% OUTPUT: "dirPath" returns the parent directory (including a full
% directory path).
% "fileNameNoPathNoExt" returns the file name with directory path and file
% extension removed.
% "fileExt" returns the file extension.
%==========================================================================
function [dirPath, fileNameNoPathNoExt, fileExt] = partitionFileName(fileName)
% [dirPath, fileNameNoPathNoExt, fileExt] = getFileNameNoPathNoExt('C:\E\NEHScans\NEH044\DPX\NEH044_000015.dpx')

% Assert that the specified file name is a string.
assert((ischar(fileName) == true), 'SoundRestoration:partitionFileName:Not-A-StringInputFileName', ...
        'Input file name is not a string; it needs to be a non-empty string specifying an existing file.');


% Find all dots in the given file name.
dotIndArr = regexp(fileName, '\.');
if isempty(dotIndArr)
    fileExt = '';
    lastInd = numel(fileName);
else
    fileExt = fileName((dotIndArr(end) + 1):end);
    lastInd = dotIndArr(end) - 1;
end

% Find all directory separators in the given full directory path name
% (these are \ for Windows and / for Linux).
fileSepIndArr = regexp(fileName, filesep);
if isempty(fileSepIndArr)
    dirPath = '';
    firstInd = 1;
else
    dirPath = fileName(1:fileSepIndArr(end));
    firstInd = fileSepIndArr(end) + 1;
end

% Determine the file name without the directory path and file extension.
fileNameNoPathNoExt = fileName(firstInd:lastInd);

return;
% end of the function "partitionFileName"
